from flask_wtf.form import FlaskForm,Form
from wtforms.fields import *
from wtforms.validators import required,length,ValidationError,number_range
import re




def dateckeck(self,data):
    res = re.match('\d\d\d\d-\d\d-\d\d',data.data)
    if not res:
        raise ValidationError('not match data string')
    print(res.group())






class LoginForm(FlaskForm):

    username = StringField(validators=[required(message='请输入用户名'),length(max=50,min=1,message='用户名不存在')])
    password = StringField(validators=[required(message='请输入密码'),length(max=16,min=6,message='密码错误')])



class DateForm(Form):

    start = StringField(validators=[dateckeck,required(message='请输入起始时间'),length(max=10,min=10,message='错误的日期')])
    end = StringField(validators=[dateckeck,required(message='请输入结束时间'),length(max=10,min=10,message='错误的日期')])

class CreateUserForm(Form):

    username = StringField(validators=[required(message='请输入用户名'),length(max=50,min=1,message='用户名长度 1~50')])
    password = StringField(validators=[required(message='请输入密码'),length(max=16,min=8,message='密码长度 8~16')])
    point = IntegerField(validators=[required(message='请输入点数'),number_range(max=2147483647,min=0,message='发送点数有误')])


class EditUserForm(Form):

    user_id = IntegerField(validators=[required('请输入用户id')])
    point = IntegerField(validators=[required('请输入用户点数'),number_range(max=2147483647,min=0,message='发送点数有误')])
    template_number = IntegerField(validators=[required('请输入用户模板数量')])
    status = IntegerField(validators=[required(message='请选择状态'),number_range(1,2)])



class PatchTemplate(Form):
    id = IntegerField(validators=[required('错误的请求'),number_range(min=1)])
    name = StringField(validators=[required(message='请输入微信公众号名')])
    wx_number = StringField(validators=[required(message='请输入微信公众号id')])
    content = StringField(validators=[required(message='请输入微信公众号代码')])
